
<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>CMAKE_EXPORT_COMPILE_COMMANDS &mdash; CMake 3.27.4 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />
    
    <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/_sphinx_javascript_frameworks_compat.js"></script>
    <script src="../_static/doctools.js"></script>
    <script src="../_static/sphinx_highlight.js"></script>
    
    <link rel="shortcut icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="CMAKE_EXPORT_PACKAGE_REGISTRY" href="CMAKE_EXPORT_PACKAGE_REGISTRY.html" />
    <link rel="prev" title="CMAKE_EXECUTE_PROCESS_COMMAND_ECHO" href="CMAKE_EXECUTE_PROCESS_COMMAND_ECHO.html" />
 

  </head><body>

    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="CMAKE_EXPORT_PACKAGE_REGISTRY.html" title="CMAKE_EXPORT_PACKAGE_REGISTRY"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="CMAKE_EXECUTE_PROCESS_COMMAND_ECHO.html" title="CMAKE_EXECUTE_PROCESS_COMMAND_ECHO"
             accesskey="P">previous</a> |</li>
  <li>
    <img src="../_static/cmake-logo-16.png" alt=""
         style="vertical-align: middle; margin-top: -2px" />
  </li>
  <li>
    <a href="https://cmake.org/">CMake</a> &#187;
  </li>
  <li>
    <a href="../index.html">3.27.4 Documentation</a> &#187;
  </li>

          <li class="nav-item nav-item-1"><a href="../manual/cmake-variables.7.html" accesskey="U">cmake-variables(7)</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">CMAKE_EXPORT_COMPILE_COMMANDS</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="cmake-export-compile-commands">
<span id="variable:CMAKE_EXPORT_COMPILE_COMMANDS"></span><h1>CMAKE_EXPORT_COMPILE_COMMANDS<a class="headerlink" href="#cmake-export-compile-commands" title="Permalink to this heading">¶</a></h1>
<div class="versionadded">
<p><span class="versionmodified added">New in version 3.5.</span></p>
</div>
<p>Enable/Disable output of compile commands during generation.</p>
<p>If enabled, generates a <code class="docutils literal notranslate"><span class="pre">compile_commands.json</span></code> file containing the exact
compiler calls for all translation units of the project in machine-readable
form.  The format of the JSON file looks like:</p>
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="p">[</span>
<span class="w">  </span><span class="p">{</span>
<span class="w">    </span><span class="s2">&quot;directory&quot;</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;/home/user/development/project&quot;</span><span class="p">,</span>
<span class="w">    </span><span class="s2">&quot;command&quot;</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;/usr/bin/c++ ... -c ../foo/foo.cc&quot;</span><span class="p">,</span>
<span class="w">    </span><span class="s2">&quot;file&quot;</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;../foo/foo.cc&quot;</span>
<span class="w">  </span><span class="p">},</span>

<span class="w">  </span><span class="p">...</span>

<span class="w">  </span><span class="p">{</span>
<span class="w">    </span><span class="s2">&quot;directory&quot;</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;/home/user/development/project&quot;</span><span class="p">,</span>
<span class="w">    </span><span class="s2">&quot;command&quot;</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;/usr/bin/c++ ... -c ../foo/bar.cc&quot;</span><span class="p">,</span>
<span class="w">    </span><span class="s2">&quot;file&quot;</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;../foo/bar.cc&quot;</span>
<span class="w">  </span><span class="p">}</span>
<span class="p">]</span>
</pre></div>
</div>
<p>This is initialized by the <span class="target" id="index-0-envvar:CMAKE_EXPORT_COMPILE_COMMANDS"></span><a class="reference internal" href="../envvar/CMAKE_EXPORT_COMPILE_COMMANDS.html#envvar:CMAKE_EXPORT_COMPILE_COMMANDS" title="CMAKE_EXPORT_COMPILE_COMMANDS"><code class="xref cmake cmake-envvar docutils literal notranslate"><span class="pre">CMAKE_EXPORT_COMPILE_COMMANDS</span></code></a> environment
variable, and initializes the <span class="target" id="index-0-prop_tgt:EXPORT_COMPILE_COMMANDS"></span><a class="reference internal" href="../prop_tgt/EXPORT_COMPILE_COMMANDS.html#prop_tgt:EXPORT_COMPILE_COMMANDS" title="EXPORT_COMPILE_COMMANDS"><code class="xref cmake cmake-prop_tgt docutils literal notranslate"><span class="pre">EXPORT_COMPILE_COMMANDS</span></code></a> target
property for all targets.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This option is implemented only by <a class="reference internal" href="../manual/cmake-generators.7.html#makefile-generators"><span class="std std-ref">Makefile Generators</span></a>
and <a class="reference internal" href="../manual/cmake-generators.7.html#ninja-generators"><span class="std std-ref">Ninja Generators</span></a>.  It is ignored on other generators.</p>
<p>This option currently does not work well in combination with
the <span class="target" id="index-0-prop_tgt:UNITY_BUILD"></span><a class="reference internal" href="../prop_tgt/UNITY_BUILD.html#prop_tgt:UNITY_BUILD" title="UNITY_BUILD"><code class="xref cmake cmake-prop_tgt docutils literal notranslate"><span class="pre">UNITY_BUILD</span></code></a> target property or the
<span class="target" id="index-0-variable:CMAKE_UNITY_BUILD"></span><a class="reference internal" href="CMAKE_UNITY_BUILD.html#variable:CMAKE_UNITY_BUILD" title="CMAKE_UNITY_BUILD"><code class="xref cmake cmake-variable docutils literal notranslate"><span class="pre">CMAKE_UNITY_BUILD</span></code></a> variable.</p>
</div>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <div>
    <h4>Previous topic</h4>
    <p class="topless"><a href="CMAKE_EXECUTE_PROCESS_COMMAND_ECHO.html"
                          title="previous chapter">CMAKE_EXECUTE_PROCESS_COMMAND_ECHO</a></p>
  </div>
  <div>
    <h4>Next topic</h4>
    <p class="topless"><a href="CMAKE_EXPORT_PACKAGE_REGISTRY.html"
                          title="next chapter">CMAKE_EXPORT_PACKAGE_REGISTRY</a></p>
  </div>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/variable/CMAKE_EXPORT_COMPILE_COMMANDS.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>document.getElementById('searchbox').style.display = "block"</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="CMAKE_EXPORT_PACKAGE_REGISTRY.html" title="CMAKE_EXPORT_PACKAGE_REGISTRY"
             >next</a> |</li>
        <li class="right" >
          <a href="CMAKE_EXECUTE_PROCESS_COMMAND_ECHO.html" title="CMAKE_EXECUTE_PROCESS_COMMAND_ECHO"
             >previous</a> |</li>
  <li>
    <img src="../_static/cmake-logo-16.png" alt=""
         style="vertical-align: middle; margin-top: -2px" />
  </li>
  <li>
    <a href="https://cmake.org/">CMake</a> &#187;
  </li>
  <li>
    <a href="../index.html">3.27.4 Documentation</a> &#187;
  </li>

          <li class="nav-item nav-item-1"><a href="../manual/cmake-variables.7.html" >cmake-variables(7)</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">CMAKE_EXPORT_COMPILE_COMMANDS</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2000-2023 Kitware, Inc. and Contributors.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
    </div>
  </body>
</html>